% For now, there are no inputs

close all;

% Create and Size the frame
scrsz = get(0,'ScreenSize');
left = 512;
f = figure('Position', [left 500 (scrsz(3))-left 2*scrsz(4)/3]);

% Ensure each frame is of the same size 
set(f, 'NextPlot', 'replacechildren');
%grid on;

% Get the size of the frame
winsize = get(f,'Position');
winsize(1:2) = [0 0];

% Length of our signal
n = 35;

% Define our input signal
x = ones(1, n);
x(8:15) = 5;

% Define the wind
u1  = ones(1, n);
u1(5:12) = 3;

u2 = sin([1:n]) + 1;
tmp(15:25) = 5;
u2(15:25) = u2(15:25)+((1/10)*(tmp(15:25)).^2);
u2d = gradient(u2);

% Output is y, initialize it to throw in this loop
y1 = x;
y2 = x.*1.1;

S_original = mean(abs(y2-y1)./y1);

% Define our grid..
dx = 1000; % [m]
dt = 120;  % [s]
N = [1:dx:n*dx];

subplot(3, 1, 1);
hold on;

% Define an array to hold legend titles
le = cell(0, 1);

plot(N, y1, 'k');
le{length(le) + 1} = ['x'];

plot(N, u1, 'r-');
le{length(le) + 1} = ['u_1'];

plot(N, u2, 'b-');
le{length(le) + 1} = ['u_2'];

hold off;
axis(gca, [0 n*dx 0 10]);
legend(le, 'Location', 'EastOutside');
grid on;

subplot(3, 1, 2);

% Define an array to hold legend titles
le = cell(0, 1);

% Movie Matrixes
%F = struct();

for I=[1:30]

	[y1 y1_d] = mex_advf_d(y1, u2, dx, dt);
	[y2 y2_d] = mex_advf_d(y2, u2, dx, dt);

	subplot(3, 1, 2);
	plot_signals(N, x, y1, y1_d, n, dx);
	subplot(3, 1, 3);
	plot_signals(N, x, y2, y2_d, n, dx);
	F(I) = getframe(f, winsize);

	% Pause to make the animation better
	% pause(0.05);
end

set(f, 'Position', [left 500 (scrsz(3))-left 2*scrsz(4)/3]);
movie(f, F, 1);

S = mean(abs(y2-y1)./y1);

sprintf('A %0.1f%% change in the input resulted in a average %0.1f%% change in the output.', S_original*100, S*100)
